home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-09-17 | 16.1 KB | 467 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWLnkCmd.cpp
- // Release Version: $ ODF 2 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "FWFrameW.hpp"
-
- #ifndef FWLNKCMD_H
- #include "FWLnkCmd.h"
- #endif
-
- #ifndef FWLNKMGR_H
- #include "FWLnkMgr.h"
- #endif
-
- #ifndef FWLNKDST_H
- #include "FWLnkDst.h"
- #endif
-
- #ifndef FWLNKSRC_H
- #include "FWLnkSrc.h"
- #endif
-
- #ifndef FWPART_H
- #include "FWPart.h"
- #endif
-
- // ----- OS Layer -----
-
- #ifndef SLODFSTR_K
- #include "SLODFStr.k"
- #endif
-
- #ifndef SLODFSTR_H
- #include "SLODFStr.h"
- #endif
-
- #ifndef FWMENUS_K
- #include "FWMenus.k"
- #endif
-
- // ----- OpenDoc Includes -----
-
- #ifndef SOM_Module_OpenDoc_StdTypes_defined
- #include <StdTypes.xh>
- #endif
-
- #ifndef SOM_ODSession_xh
- #include <ODSessn.xh>
- #endif
-
- #ifndef SOM_ODDraft_xh
- #include <Draft.xh>
- #endif
-
- #ifndef SOM_ODLinkSource_xh
- #include <LinkSrc.xh>
- #endif
-
- //========================================================================================
- // Runtime Info
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment odflinking
- #endif
-
- FW_DEFINE_AUTO(FW_CPrivCreateLinkSourceCommand)
- FW_DEFINE_AUTO(FW_CPrivCreateLinkCommand)
-
- //========================================================================================
- // FW_CPrivCreateLinkSourceCommand class
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivCreateLinkSourceCommand constructor
- //----------------------------------------------------------------------------------------
- FW_CPrivCreateLinkSourceCommand::FW_CPrivCreateLinkSourceCommand(Environment* ev,
- FW_CFrame* frame,
- FW_CLinkManager* linkMgr,
- FW_CLinkSource* pendingLink)
- : FW_CCommand(ev, FW_kCreateLinkSourceCommand, frame, FW_kCanUndo),
- fLinkMgr(linkMgr),
- fLinkSource(pendingLink)
- {
- // This command's Undo strings don't matter, because this transaction is always
- // bracketted by kODBegin/EndAction transactions.
- this->SetMenuStrings(ev, "Undo", "Redo");
-
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivCreateLinkSourceCommand destructor
- //----------------------------------------------------------------------------------------
- FW_CPrivCreateLinkSourceCommand::~FW_CPrivCreateLinkSourceCommand()
- {
- FW_START_DESTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivCreateLinkSourceCommand::CommitUndone
- //----------------------------------------------------------------------------------------
- void FW_CPrivCreateLinkSourceCommand::CommitUndone(Environment*)
- {
- if (fLinkSource)
- {
- delete fLinkSource;
- fLinkSource = NULL;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivCreateLinkSourceCommand::DoIt
- //----------------------------------------------------------------------------------------
- void FW_CPrivCreateLinkSourceCommand::DoIt(Environment* ev)
- {
- if (fLinkSource)
- {
- FW_CPart* part = GetPart(ev);
- ODLinkSource* odLinkSource = part->GetDraft(ev)->CreateLinkSource(ev, part->GetODPart(ev));
- fLinkSource->SetODLinkSource(ev, odLinkSource);
-
- //--- Establish the link ---
- fLinkMgr->AddToSourceLinkList(ev, fLinkSource);
- fLinkSource->PrivLinkEstablished(ev);
- }
- else
- {
- // if nothing comes of this, then it won't cause any change!
- this->SetCausesChange(ev, false);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivCreateLinkSourceCommand::GetODLinkSource
- //----------------------------------------------------------------------------------------
- ODLinkSource* FW_CPrivCreateLinkSourceCommand::GetODLinkSource(Environment* ev)
- {
- if (fLinkSource)
- return fLinkSource->GetODLinkSource(ev);
- return NULL;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivCreateLinkSourceCommand::UndoIt
- //----------------------------------------------------------------------------------------
- void FW_CPrivCreateLinkSourceCommand::UndoIt(Environment* ev)
- {
- if (fLinkSource)
- fLinkMgr->BreakSourceLink(ev, fLinkSource); // calls RemoveFromSourceLinkList
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivCreateLinkSourceCommand::RedoIt
- //----------------------------------------------------------------------------------------
- void FW_CPrivCreateLinkSourceCommand::RedoIt(Environment* ev)
- {
- //--- Re-establish the link ---
- if (fLinkSource)
- fLinkMgr->RestoreSourceLink(ev, fLinkSource); // calls AddToSourceLinkList
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivCreateLinkSourceCommand::PropagateChanges
- //----------------------------------------------------------------------------------------
- void FW_CPrivCreateLinkSourceCommand::PropagateChanges(Environment* ev, ODUpdateID id )
- {
- FW_UNUSED(id);
-
- // just creating or removing link source should not propagate out the frame hierarchy, because
- // link updates only deal with content, not with contained links. The link source
- // contains existing, unchanged content.
-
- // It is a change to the document, so just dirty stuff
- GetPart(ev)->Changed(ev);
- }
-
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivCreateLinkSourceCommand::SetLinkSource
- //----------------------------------------------------------------------------------------
- void FW_CPrivCreateLinkSourceCommand::SetLinkSource(Environment* ev, FW_CLinkSource* linkSrc)
- {
- FW_ASSERT(fLinkSource == NULL);
- FW_ASSERT(linkSrc != NULL);
-
- fLinkSource = linkSrc;
-
- // everything was suppressed during execute. It just placed an action in the undo history
- this->DoIt(ev);
- this->SetCausesChange(ev, true);
- this->PropagateChanges(ev);
- }
-
-
- //========================================================================================
- // FW_CPrivCreateLinkCommand class
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivCreateLinkCommand constructor
- //----------------------------------------------------------------------------------------
- FW_CPrivCreateLinkCommand::FW_CPrivCreateLinkCommand(Environment* ev,
- FW_CFrame* frame,
- FW_CLinkManager* linkMgr,
- FW_Boolean fromClipboard)
- : FW_CCommand(ev, FW_kCreateLinkCommand, frame, FW_kCanUndo),
- fLinkMgr(linkMgr),
- fLink(NULL)
- {
- if (fromClipboard)
- {
- SetActionType(ev, kODBeginAction);
- // ODPG says to use kODEndAction, but my PasteAs command adds its Undo action
- // _after_ the link has been created, so I have to reverse the order of transactions
-
- // Set Undo strings to the ones used for the Paste As command
- FW_CString undoString;
- FW_CString redoString;
- ::FW_PrivLoadUndoStrings(ev, FW_kUndoPasteAsMsg, undoString, redoString);
- SetMenuStrings(ev, undoString, redoString);
- }
- else
- {
- // For Drag&Drop use the default action type, kODSingleAction.
- // The Undo strings don't matter, because this transaction will be
- // bracketted by kODBegin/EndAction transactions.
- this->SetMenuStrings(ev, "", "");
- }
-
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivCreateLinkCommand destructor
- //----------------------------------------------------------------------------------------
- FW_CPrivCreateLinkCommand::~FW_CPrivCreateLinkCommand()
- {
- FW_START_DESTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivCreateLinkCommand::CommitUndone
- //----------------------------------------------------------------------------------------
- void FW_CPrivCreateLinkCommand::CommitUndone(Environment*)
- {
- // The link creation was Undone
- delete fLink;
- fLink = NULL;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivCreateLinkCommand::DoIt
- //----------------------------------------------------------------------------------------
- void FW_CPrivCreateLinkCommand::DoIt(Environment* ev)
- {
- FW_UNUSED(ev);
- // The main purpose of this command is to add a transaction to the Undo history
- FW_ASSERT(GetCanUndo(ev));
- // Nothing else to do
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivCreateLinkCommand::UndoIt
- //----------------------------------------------------------------------------------------
- void FW_CPrivCreateLinkCommand::UndoIt(Environment* ev)
- {
- //--- Remove the link ---
- FW_ASSERT(fLink);
-
- // It's not necessary to BreakDestinationLink. That involves changing any embedded
- // frame's link status, but they've been or are being removed, and will, if this is
- // redone, be reinstated with the same link status. Besides that,
- // ODFrame::ChangeLinkStatus crashes when called on a detatched frame!
-
-
- // just unregister the link and remove it from the part.
- fLink->Unregister(ev);
- fLinkMgr->RemoveFromDestLinkList(ev, fLink);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivCreateLinkCommand::RedoIt
- //----------------------------------------------------------------------------------------
- void FW_CPrivCreateLinkCommand::RedoIt(Environment* ev)
- {
- //--- Restore the link ---
- FW_ASSERT(fLink);
-
- // add link to back to linkmgr, then register it. It won't be able to get any resultant
- // update if it's not added back first
-
- fLinkMgr->AddToDestLinkList(ev, fLink);
- fLink->Register(ev, GetPart(ev));
- }
-
- //========================================================================================
- // FW_CBreakLinkCommand class
- //========================================================================================
-
- FW_DEFINE_AUTO(FW_CBreakLinkCommand)
-
- //----------------------------------------------------------------------------------------
- // FW_CBreakLinkCommand constructor
- //----------------------------------------------------------------------------------------
- FW_CBreakLinkCommand::FW_CBreakLinkCommand(Environment* ev,
- FW_CFrame* frame,
- FW_CLinkDestination* link,
- FW_CLinkManager* linkMgr)
- : FW_CCommand(ev, FW_kBreakLinkCommand, frame, FW_kCanUndo),
- fLink(link),
- fLinkMgr(linkMgr)
- {
- FW_CString undoString;
- FW_CString redoString;
-
- ::FW_PrivLoadUndoStrings(ev, FW_kUndoBreakLinkMsg, undoString, redoString);
- SetMenuStrings(ev, undoString, redoString);
-
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CBreakLinkCommand destructor
- //----------------------------------------------------------------------------------------
- FW_CBreakLinkCommand::~FW_CBreakLinkCommand()
- {
- FW_START_DESTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CBreakLinkCommand::CommitDone
- //----------------------------------------------------------------------------------------
- void FW_CBreakLinkCommand::CommitDone(Environment* ev)
- {
- FW_UNUSED(ev);
- // Delete the saved link destination only if the command was not undone
- delete fLink;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CBreakLinkCommand::DoIt
- //----------------------------------------------------------------------------------------
- void FW_CBreakLinkCommand::DoIt(Environment* ev)
- {
- //-- Break the link --
- fLinkMgr->BreakDestinationLink(ev, fLink);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CBreakLinkCommand::UndoIt
- //----------------------------------------------------------------------------------------
- void FW_CBreakLinkCommand::UndoIt(Environment* ev)
- {
- //-- Restore the broken link --
- fLinkMgr->RestoreDestinationLink(ev, fLink);
- GetPart(ev)->Changed(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CBreakLinkCommand::RedoIt
- //----------------------------------------------------------------------------------------
- void FW_CBreakLinkCommand::RedoIt(Environment* ev)
- {
- fLinkMgr->BreakDestinationLink(ev, fLink);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CBreakLinkCommand::PropagateChanges
- //----------------------------------------------------------------------------------------
- void FW_CBreakLinkCommand::PropagateChanges(Environment* ev, ODUpdateID )
- {
- // removing or adding a link doesn't need to propagate outwards to any
- // containing publishers, because only the underlying content is actually
- // linked, not the contained links themselves. So just mark the part dirty
-
- GetPart(ev)->Changed(ev);
- }
-
- //========================================================================================
- // FW_CBreakLinkSourceCommand class
- //========================================================================================
-
- FW_DEFINE_AUTO(FW_CBreakLinkSourceCommand)
-
- //----------------------------------------------------------------------------------------
- // FW_CBreakLinkSourceCommand constructor
- //----------------------------------------------------------------------------------------
- FW_CBreakLinkSourceCommand::FW_CBreakLinkSourceCommand(Environment* ev,
- FW_CFrame* frame,
- FW_CLinkSource* linkSource,
- FW_CLinkManager* linkMgr)
- : FW_CCommand(ev, FW_kBreakLinkCommand, frame, FW_kCanUndo),
- fLinkSource(linkSource),
- fLinkMgr(linkMgr)
- {
- FW_CString undoString;
- FW_CString redoString;
-
- ::FW_PrivLoadUndoStrings(ev, FW_kUndoBreakLinkSourceMsg, undoString, redoString);
- SetMenuStrings(ev, undoString, redoString);
-
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CBreakLinkSourceCommand destructor
- //----------------------------------------------------------------------------------------
- FW_CBreakLinkSourceCommand::~FW_CBreakLinkSourceCommand()
- {
- FW_START_DESTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CBreakLinkSourceCommand::CommitDone
- //----------------------------------------------------------------------------------------
- void FW_CBreakLinkSourceCommand::CommitDone(Environment* ev)
- {
- FW_UNUSED(ev);
- // Delete the saved link source only if the command was not undone
- delete fLinkSource;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CBreakLinkSourceCommand::DoIt
- //----------------------------------------------------------------------------------------
- void FW_CBreakLinkSourceCommand::DoIt(Environment* ev)
- {
- //-- Break the link --
- fLinkMgr->BreakSourceLink(ev, fLinkSource);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CBreakLinkSourceCommand::UndoIt
- //----------------------------------------------------------------------------------------
- void FW_CBreakLinkSourceCommand::UndoIt(Environment* ev)
- {
- //-- Restore the broken link --
- fLinkMgr->RestoreSourceLink(ev, fLinkSource);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CBreakLinkSourceCommand::RedoIt
- //----------------------------------------------------------------------------------------
- void FW_CBreakLinkSourceCommand::RedoIt(Environment* ev)
- {
- fLinkMgr->BreakSourceLink(ev, fLinkSource);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CBreakLinkSourceCommand::PropagateChanges
- //----------------------------------------------------------------------------------------
- void FW_CBreakLinkSourceCommand::PropagateChanges(Environment* ev, ODUpdateID)
- {
- // removing or adding a link doesn't need to propagate outwards to any
- // containing publishers, because only the underlying content is actually
- // linked, not the contained links themselves. So just mark the part dirty
-
- GetPart(ev)->Changed(ev);
- }
-
-